home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume3 / laserjet-printcap < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  4.2 KB

  1. From: genrad!ihnp4!psivax!friesen (Stanley Friesen)
  2. Subject: LaserJet sources for BSD 4.2+
  3. Newsgroups: mod.sources
  4. Approved: jpn@panda.UUCP
  5.  
  6. Mod.sources:  Volume 3, Issue 9
  7. Submitted by: ihnp4!psivax!friesen (Stanley Friesen)
  8.  
  9.  
  10.  
  11.     The following contains the filters and printcap entry which we
  12. use to run a LaserJet printer as a spooled printer device under lpd.
  13. It takes care of *most* of the funnies.  The worst problem is still
  14. the buffer overflow, since even using LLITOUT UNIX does not stop
  15. output fast enough after a ^S for the LaserJet. We have solved that
  16. problem by sticking a Microbuffer external buffer between the computer
  17. and the LaserJet, our system now works quite smoothly.
  18. ----------------------------------Cut Here--------------------------------
  19. #! /bin/sh
  20. # This is a shell archive, meaning:
  21. # 1. Remove everything above the #! /bin/sh line.
  22. # 2. Save the resulting text in a file.
  23. # 3. Execute the file with /bin/sh (not csh) to create the files:
  24. #    hpf.c
  25. #    lzcat.c
  26. #    printcap
  27. # This archive created: Tue Sep  3 10:17:46 1985
  28. export PATH; PATH=/bin:$PATH
  29. echo shar: extracting "'hpf.c'" '(1665 characters)'
  30. if test -f 'hpf.c'
  31. then
  32.     echo shar: will not over-write existing file "'hpf.c'"
  33. else
  34. cat << \SHAR_EOF > 'hpf.c'
  35. #include "stdio.h"
  36. #include <signal.h>
  37.  
  38. int nomap = 0, is_of = 1;
  39.  
  40. main(ac, av)
  41. int ac;
  42. char **av;
  43. {
  44.     while(ac > 1 && av[1][0] == '-')
  45.     {
  46.     switch(av[1][1])
  47.     {
  48.         case 'c':
  49.         nomap = 1;
  50.         break;
  51.         case 'n': case 'h':
  52.         is_of = 0;
  53.         break;
  54.         default: break;
  55.     }
  56.     ac--;
  57.     av++;
  58.     }
  59.  
  60.     lzinit();
  61.     hpcat();
  62.     exit(0);
  63. }
  64.  
  65. #include <sgtty.h> 
  66.  
  67. lzinit()
  68. {
  69.     struct sgttyb nbuf;
  70.     unsigned long lbits;
  71.  
  72.     setbuf(stdout, NULL);
  73.     /* Work around to by-pass bug in terminal driver and force LITOUT */
  74.     lbits = LMDMBUF|LLITOUT;
  75.     ioctl(fileno(stdout), TIOCLSET, &lbits);
  76.     ioctl(fileno(stdout), TIOCGETP, &nbuf);
  77.     nbuf.sg_flags &= ~(ECHO|XTABS|CRMOD);  /* While we're at it, set the mode */
  78.     ioctl(fileno(stdout), TIOCSETP, &nbuf);
  79.  
  80.     fputs("\033&k3G", stdout);    /* Set device to sane mode    */
  81. }
  82.  
  83. hpcat()
  84. {
  85.     register int c, cnt = 0;
  86.  
  87.     while((c = getchar()) != EOF)
  88.     {
  89.  
  90.     if(c == '\t')
  91.     {
  92.         do {
  93.         delay();
  94.         putchar(' ');
  95.         cnt++;
  96.         } while(cnt%8 != 0);
  97.     }
  98.     else if(is_of && c == '\031')
  99.     {
  100.         if(getchar() == '\001') kill(getpid(), SIGSTOP);
  101.     }
  102.     else
  103.     {
  104.         delay();
  105.         putchar(c);
  106.         if(c == '\f' || c == '\n') 
  107.         {
  108.         cnt = 0;
  109.         }
  110.         else cnt++;
  111.     }
  112.     }
  113. }
  114.  
  115. #include <sys/time.h> 
  116.  
  117. struct timeval tm = {0, 1500};
  118.  
  119. delay()
  120. {
  121.     select(0, 0, 0, 0, &tm);
  122. }
  123.  
  124. /*    Old version, hope to use again later
  125. #include <sys/time.h> 
  126. #include <signal.h>
  127.  
  128. int wakeup;
  129.  
  130. void nullfunc(){
  131.     wakeup = 1;
  132. }
  133.  
  134. struct itimerval tm = {{0, 0}, {0, 1500}};
  135.  
  136. delay()
  137. {
  138.  
  139.     void nullfunc();
  140.  
  141.     signal(SIGALRM, nullfunc);
  142.     wakeup = 0;
  143.     if(setitimer(ITIMER_REAL, &tm, NULL)) exit(1);
  144.     while(wakeup == 0) sigpause(0);
  145. }
  146. */
  147. SHAR_EOF
  148. fi # end of overwriting check
  149. echo shar: extracting "'lzcat.c'" '(695 characters)'
  150. if test -f 'lzcat.c'
  151. then
  152.     echo shar: will not over-write existing file "'lzcat.c'"
  153. else
  154. cat << \SHAR_EOF > 'lzcat.c'
  155. #include "stdio.h"
  156.  
  157. int nomap = 0;
  158.  
  159. main(ac, av)
  160. int ac;
  161. char **av;
  162. {
  163.  
  164.     lzinit();
  165.     lzcat();
  166.     exit(0);
  167. }
  168.  
  169. #include <sgtty.h> 
  170.  
  171. lzinit()
  172. {
  173.     struct sgttyb nbuf;
  174.     unsigned long lbits;
  175.  
  176.     setbuf(stdout, NULL);
  177.     /* Work around to by-pass bug in terminal driver and force LITOUT */
  178.     lbits = LMDMBUF|LLITOUT;
  179.     ioctl(fileno(stdout), TIOCLSET, &lbits);
  180.     ioctl(fileno(stdout), TIOCGETP, &nbuf);
  181.     nbuf.sg_flags &= ~(ECHO|XTABS|CRMOD);  /* While we're at it, set the mode */
  182.     ioctl(fileno(stdout), TIOCSETP, &nbuf);
  183.  
  184.     fputs("\033&k3G", stdout);    /* Set device to sane mode    */
  185. }
  186.  
  187. lzcat()
  188. {
  189.     register int c;
  190.  
  191.     while((c = getchar()) != EOF)
  192.     {
  193.     putchar(c);
  194.     }
  195. }
  196. SHAR_EOF
  197. fi # end of overwriting check
  198. echo shar: extracting "'printcap'" '(201 characters)'
  199. if test -f 'printcap'
  200. then
  201.     echo shar: will not over-write existing file "'printcap'"
  202. else
  203. cat << \SHAR_EOF > 'printcap'
  204. lz|laserjet|Hewlett-Packard Laserjet:\
  205.     :lp=/dev/tty23:sd=/usr/spool/lqd:br#9600:pw#132:pl#60:\
  206.     :xs#060:fc#0177477:lf=/usr/adm/lpd-errs:if=/usr/local/hpf:\
  207.     :of=/usr/local/hpf:vf=/usr/local/lzcat:rs:
  208. SHAR_EOF
  209. fi # end of overwriting check
  210. #    End of shell archive
  211. exit 0
  212.  
  213.